home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / mfb / RCS / mfbclip.c,v < prev    next >
Encoding:
Text File  |  1990-02-15  |  6.4 KB  |  267 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     90.02.14.19.57.59;  author tve;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @Original X11R4 distribution
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/***********************************************************
  27. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  28. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  29.  
  30.                         All Rights Reserved
  31.  
  32. Permission to use, copy, modify, and distribute this software and its 
  33. documentation for any purpose and without fee is hereby granted, 
  34. provided that the above copyright notice appear in all copies and that
  35. both that copyright notice and this permission notice appear in 
  36. supporting documentation, and that the names of Digital or MIT not be
  37. used in advertising or publicity pertaining to distribution of the
  38. software without specific, written prior permission.  
  39.  
  40. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  41. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  42. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  43. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  44. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  45. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  46. SOFTWARE.
  47.  
  48. ******************************************************************/
  49. /* $XConsortium: mfbclip.c,v 5.2 89/11/30 14:21:50 keith Exp $ */
  50. #include "X.h"
  51. #include "miscstruct.h"
  52. #include "pixmapstr.h"
  53. #include "scrnintstr.h"
  54. #include "regionstr.h"
  55. #include "gc.h"
  56. #include "maskbits.h"
  57. #include "mi.h"
  58.  
  59. #define ADDRECT(reg,r,fr,rx1,ry1,rx2,ry2)            \
  60. if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&            \
  61.     (!((reg)->data->numRects &&                    \
  62.        ((r-1)->y1 == (ry1)) &&                    \
  63.        ((r-1)->y2 == (ry2)) &&                    \
  64.        ((r-1)->x1 <= (rx1)) &&                    \
  65.        ((r-1)->x2 >= (rx2)))))                    \
  66. {                                \
  67.     if ((reg)->data->numRects == (reg)->data->size)        \
  68.     {                                \
  69.     miRectAlloc(reg, 1);                    \
  70.     fr = REGION_BOXPTR(reg);                \
  71.     r = fr + (reg)->data->numRects;                \
  72.     }                                \
  73.     r->x1 = (rx1);                        \
  74.     r->y1 = (ry1);                        \
  75.     r->x2 = (rx2);                        \
  76.     r->y2 = (ry2);                        \
  77.     (reg)->data->numRects++;                    \
  78.     if(r->x1 < (reg)->extents.x1)                \
  79.     (reg)->extents.x1 = r->x1;                \
  80.     if(r->x2 > (reg)->extents.x2)                \
  81.     (reg)->extents.x2 = r->x2;                \
  82.     r++;                            \
  83. }
  84.  
  85. /* Convert bitmap clip mask into clipping region. 
  86.  * First, goes through each line and makes boxes by noting the transitions
  87.  * from 0 to 1 and 1 to 0.
  88.  * Then it coalesces the current line with the previous if they have boxes
  89.  * at the same X coordinates.
  90.  */
  91. RegionPtr
  92. mfbPixmapToRegion(pPix)
  93.     PixmapPtr    pPix;
  94. {
  95.     register RegionPtr    pReg;
  96.     register unsigned    *pw, w;
  97.     register int    ib;
  98.     int            width, h, base, rx1, crects;
  99.     unsigned int    *pwLineEnd;
  100.     int            irectPrevStart, irectLineStart;
  101.     register BoxPtr    prectO, prectN;
  102.     BoxPtr        FirstRect, rects, prectLineStart;
  103.     Bool        fInBox, fSame;
  104.     register unsigned    mask0 = mask[0];
  105.  
  106.  
  107.     pReg = (*pPix->drawable.pScreen->RegionCreate)(NULL, 1);
  108.     if(!pReg)
  109.     return NullRegion;
  110.     FirstRect = REGION_BOXPTR(pReg);
  111.     rects = FirstRect;
  112.     width = pPix->drawable.width;
  113.     pReg->extents.x1 = width - 1;
  114.     pReg->extents.x2 = 0;
  115.     pw = (unsigned int  *)pPix->devPrivate.ptr;
  116.     irectPrevStart = -1;
  117.     for(h = 0; h < pPix->drawable.height; h++)
  118.     {
  119.     irectLineStart = rects - FirstRect;
  120.     /* If the Screen left most bit of the word is set, we're starting in
  121.      * a box */
  122.     if(*pw & mask0)
  123.     {
  124.         fInBox = TRUE;
  125.         rx1 = 0;
  126.     }
  127.     else
  128.         fInBox = FALSE;
  129.     /* Process all words which are fully in the pixmap */
  130.     pwLineEnd = pw + (width >> 5);
  131.     for (base = 0; pw < pwLineEnd; base += 32)
  132.     {
  133.         w = *pw++;
  134.         if (fInBox)
  135.         {
  136.         if (!~w)
  137.             continue;
  138.         }
  139.         else
  140.         {
  141.         if (!w)
  142.             continue;
  143.         }
  144.         for(ib = 0; ib < 32; ib++)
  145.         {
  146.             /* If the Screen left most bit of the word is set, we're
  147.          * starting a box */
  148.         if(w & mask0)
  149.         {
  150.             if(!fInBox)
  151.             {
  152.             rx1 = base + ib;
  153.             /* start new box */
  154.             fInBox = TRUE;
  155.             }
  156.         }
  157.         else
  158.         {
  159.             if(fInBox)
  160.             {
  161.             /* end box */
  162.             ADDRECT(pReg, rects, FirstRect,
  163.                 rx1, h, base + ib, h + 1);
  164.             fInBox = FALSE;
  165.             }
  166.         }
  167.         /* Shift the word VISUALLY left one. */
  168.         w = SCRLEFT(w, 1);
  169.         }
  170.     }
  171.     if(width & 0x1F)
  172.     {
  173.         /* Process final partial word on line */
  174.         w = *pw++;
  175.         for(ib = 0; ib < (width & 0x1F); ib++)
  176.         {
  177.             /* If the Screen left most bit of the word is set, we're
  178.          * starting a box */
  179.         if(w & mask0)
  180.         {
  181.             if(!fInBox)
  182.             {
  183.             rx1 = base + ib;
  184.             /* start new box */
  185.             fInBox = TRUE;
  186.             }
  187.         }
  188.         else
  189.         {
  190.             if(fInBox)
  191.             {
  192.             /* end box */
  193.             ADDRECT(pReg, rects, FirstRect,
  194.                 rx1, h, base + ib, h + 1);
  195.             fInBox = FALSE;
  196.             }
  197.         }
  198.         /* Shift the word VISUALLY left one. */
  199.         w = SCRLEFT(w, 1);
  200.         }
  201.     }
  202.     /* If scanline ended with last bit set, end the box */
  203.     if(fInBox)
  204.     {
  205.         ADDRECT(pReg, rects, FirstRect,
  206.             rx1, h, base + (width & 0x1f), h + 1);
  207.     }
  208.     /* if all rectangles on this line have the same x-coords as
  209.      * those on the previous line, then add 1 to all the previous  y2s and 
  210.      * throw away all the rectangles from this line 
  211.      */
  212.     fSame = FALSE;
  213.     if(irectPrevStart != -1)
  214.     {
  215.         crects = irectLineStart - irectPrevStart;
  216.         if(crects == ((rects - FirstRect) - irectLineStart))
  217.         {
  218.             prectO = FirstRect + irectPrevStart;
  219.             prectN = prectLineStart = FirstRect + irectLineStart;
  220.         fSame = TRUE;
  221.             while(prectO < prectLineStart)
  222.         {
  223.             if((prectO->x1 != prectN->x1) || (prectO->x2 != prectN->x2))
  224.             {
  225.               fSame = FALSE;
  226.               break;
  227.             }
  228.             prectO++;
  229.             prectN++;
  230.         }
  231.         if (fSame)
  232.         {
  233.             prectO = FirstRect + irectPrevStart;
  234.             while(prectO < prectLineStart)
  235.             {
  236.             prectO->y2 += 1;
  237.             prectO++;
  238.             }
  239.             rects -= crects;
  240.             pReg->data->numRects -= crects;
  241.         }
  242.         }
  243.     }
  244.     if(!fSame)
  245.         irectPrevStart = irectLineStart;
  246.     }
  247.     if (!pReg->data->numRects)
  248.     pReg->extents.x1 = pReg->extents.x2 = 0;
  249.     else
  250.     {
  251.     pReg->extents.y1 = REGION_BOXPTR(pReg)->y1;
  252.     pReg->extents.y2 = REGION_END(pReg)->y2;
  253.     if (pReg->data->numRects == 1)
  254.     {
  255.         xfree(pReg->data);
  256.         pReg->data = (RegDataPtr)NULL;
  257.     }
  258.     }
  259. #ifdef DEBUG
  260.     if (!miValidRegion(pReg))
  261.     FatalError("Assertion failed file %s, line %d: expr\n", __FILE__, __LINE__);
  262. #endif
  263.     return(pReg);
  264. }
  265.  
  266. @
  267.